package com.hr.设计模式.单例模式;

/**
 * @author 周恒哲
 * @date 2020/06/17
 * 双重检测锁
 **/
public class Singleton4 {
    /**
     * volatile：禁止指令重排，不保证原子性
     *
     */
    private volatile static Singleton4 singleton;

    private Singleton4() {
    }
    public  static Singleton4 getSingleton(){
        if(singleton==null){
            synchronized (Singleton4.class){
                if (singleton==null){
                    singleton=new Singleton4();
                }
            }
        }
        return singleton;
    }

}
